PyQt5+VTK环境搭建 |
您所在的位置:网站首页 › pyqt 反编译 › PyQt5+VTK环境搭建 |
PyQt5+VTK环境搭建
VTK 简介及安装VTK 介绍VTK 在 Python 环境下安装方法一 安装 anaconda,使用 conda install 安装:适用于 python3适用于 python 2
方法二:镜像安装检测安装成功
VTK简单示例绘制立方体
PyQt5中引入VTK渲染窗口PyQt5中使用VTK读取STL文件VTK支持的3D文件格式
VTK 简介及安装
VTK 介绍
VTK(visualization toolkit)是一个开源的免费软件系统,主要用于三维计算机图形学、图像处理和可视化。Vtk 是在面向对象原理的基础上设计和实现的,它的内核是用 C++ 构建的,包含有大约 250,000 行代码,2000 多个类,还包含有几个转换界面,因此也可以自由的通过 Java,Tcl/Tk 和 Python 各种语言使用 VTK。 VTK 是一个开放源码、自由获取的软件系统,全世界的数以千计的研究人员和开发人员用它来进行 3D 计算机图形,图像处理,可视化。VTK 包含一个 c++类库,众多的翻译接口层,包括 Tcl/Tk,Java,Python。 Visualization Toolkit 是一个用于可视化应用程序构造与运行的支撑环境,它是在三维函数库 OpenGL 的基础上采用面向对象的设计方法发展起来的,它将我们在可视化开发过程中会经常遇到的细节屏蔽起来,并将一些常用的算法封装起来。比如 Visualization Toolkit 将我们在表面重建中比较常见的 MarchingCubes 算法封装起来,以类的形式给我们以支持,这样我们在对三维规则点阵数据进行表面重建时就不必再重复编写 MarchingCubes 算法的代码,而直接使用 Visualization Toolkit 中已经提供的 vtkMarchingCubes 类。Visualization Toolkit 是给从事可视化应用程序开发工作的研究人员提供直接的技术支持的一个强大的可视化开发工具。 VTK 在 Python 环境下安装 方法一 安装 anaconda,使用 conda install 安装:注意不同版本的 Python 对应不同的命令。 适用于 python3install -n envA -c menpo vtk=7 python=3 或者具体到某个版本: conda install -n envB -c menpo vtk=7 python=3.5 适用于 python 2conda install -n envC vtk python=2 适用于 3.6: conda install -c clinicalgraphics vtk=7.1.0 以上的命令都可以不加版本号 方法二:镜像安装由于国内的镜像里没有 vtk,所以直接用 conda 安装会非常慢,推荐下载 whl 文件后使用 pip 安装。 提供一个下载 VTK 的 whl 文件的网址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#vtk 我是 win10 系统 64 位下,使用的 python3.7,下载的是:VTK‑8.1.2‑cp37‑cp37m‑win32.whl 然后进入下载目录,启动 cmd, window power shell 或者 git bash,输入命令: pip install VTK-7.1.1-cp36-cp36m-win_amd64.whl 完成安装。 安装完成后,在使用处导入vtk包即可。 检测安装成功示例代码: import vtk cone_a = vtk.vtkConeSource() coneMapper = vtk.vtkPolyDataMapper() coneMapper.SetInputConnection(cone_a.GetOutputPort()) coneActor = vtk.vtkActor() coneActor.SetMapper(coneMapper) ren1 = vtk.vtkRenderer() ren1.AddActor(coneActor) ren1.SetBackground(1.0, 1.0, 1.0) ren1.SetBackground2(0.1, 0.2, 0.4) ren1.SetGradientBackground(1) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) renWin.SetSize(300, 300) renWin.Render() iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) iren.Initialize() iren.Start()运行结果如图所示: VTK简单示例 绘制立方体 #!/usr/bin/env python # This is (almost) a direct C++ to Python transliteration of # /Examples/DataManipulation/Cxx/Cube.cxx from the VTK # source distribution, which "shows how to manually create vtkPolyData" # # A convenience function, mkVtkIdList(), has been added and one if/else # so the example also works in version 6 or later. # # Lines like `obj->Delete()` have been transliterated as `del obj` to, # preserve the resemblance to the original C++ example, although I # doubt this achieves anything beyond what Python's garbage collection # would do anyway. import vtk # Makes a vtkIdList from a Python iterable. I'm kinda surprised that # this is necessary, since I assumed that this kind of thing would # have been built into the wrapper and happen transparently, but it # seems not. def mkVtkIdList(it): vil = vtk.vtkIdList() for i in it: vil.InsertNextId(int(i)) return vil # 绘制通用方法 def myShow(cube): # Now we'll look at it. cubeMapper = vtk.vtkPolyDataMapper() if vtk.VTK_MAJOR_VERSION |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |